//{=========================================================================
//! @file C6.c
//! @date 05.10.2013 4:51
//! @author Andrey Drobyshev <immortalguardian1@gmail.com>
//! @ version 1.0
//!
//! @par	Conditions:
//! 		The program reads firstly a non-negative number N and
//!         secondly N natural numbers. It displays the numbers
//!         that haven't squares of any other numbers among their dividers.
//}=========================================================================

#include <stdio.h>
#include <math.h>

//{======================================================================
//! Function findsquares - search for numbers have squares of any other
//! numbers among their dividers.
//!
//! @param      c   -   The number we need to check
//!
//! @return     0 if there's no squares among the number's dividers
//!             1 in the other case
//!
//! @note       The function uses function "isitsquare".
//}======================================================================

int findsquares ( unsigned int c);

//{==========================================================================
//! Function isitsquare - checks out if a number is square of another number
//!
//! @param      m   -   The number we need to check
//!
//! @return     1 if the number is square of another one
//!             0 in the other case
//}==========================================================================

int isitsquare ( unsigned int m);

//{=========================================================================
//! Function main - prints welcome messages and the result,
//! manages all the program execution.
//!
//! @return     0 on success
//!
//! @note       The function uses the function "findsquares".
//}==========================================================================

int main ()
{
    printf ( "#Hello!\n"
            "#This program ask you to enter few natural numbers "
            "and prints back only those of them which haven't "
            "squares of any other numbers among their dividers.\n"
            "#Please enter the number of numbers: ");

    unsigned int n = 0;

	scanf ( "%u", &n);
	printf ( "\n");
	printf ( "#Now enter your numbers with the spaces between: ");

	unsigned int i = 0, m = 0;

	for ( i = 1; i <= n; i++)
	{
		scanf ( "%d", &m);
		if ( !( findsquares ( m)))
			printf( "%u ", m);
	}
	printf ( "\n");
	return 0;
}

int findsquares ( unsigned int c)
{
	int i = 0;

	for ( i = 2; i <= ( c / 2); i++)
		if ( ( c % i) == 0)
			if ( isitsquare ( i))
				return 1;
	if ( isitsquare ( c))
		return 1;
	return 0;
}

isitsquare ( unsigned int m)
{
	int c = 0;
	c = round ( sqrt ( m));
	if ( ( c * c) == m)
		return 1;
	else
		return 0;
}
